import struct

output_file = 'index_table.py'

with open(output_file, 'w', encoding='utf-8') as file:
	file.write('index_table = {')

	for i in range(65535):
		hi_byte = i >> 8
		lo_byte = i & 0xff
		hz = struct.pack('<BB', hi_byte, lo_byte)

		try:
			hz = hz.decode(encoding='gb2312')
			if len(hz) == 1:
				code_unicode = hz.encode(encoding='unicode-escape')
				file.write('0x' + str(code_unicode)[5:-1] + ': ') 
				
				code_gb2312 = hz.encode(encoding='gb2312')
				file.write('0x%04x' % (code_gb2312[0] * 256 + code_gb2312[1]) + ', ')
		except:
			pass

	file.write('}')
